using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Markup;
namespace Microsoft.Expression.Interactivity.Core
{
	[ContentProperty("Conditions")]
	public class ConditionalExpression : DependencyObject, ICondition
	{
		public static readonly DependencyProperty ConditionsProperty = DependencyProperty.Register("Conditions", typeof(ConditionCollection), typeof(ConditionalExpression), new PropertyMetadata(null));
		public static readonly DependencyProperty ForwardChainingProperty = DependencyProperty.Register("ForwardChaining", typeof(ForwardChaining), typeof(ConditionalExpression), new PropertyMetadata(ForwardChaining.And));
		public ForwardChaining ForwardChaining
		{
			get
			{
				return (ForwardChaining)base.GetValue(ConditionalExpression.ForwardChainingProperty);
			}
			set
			{
				base.SetValue(ConditionalExpression.ForwardChainingProperty, value);
			}
		}
		public ConditionCollection Conditions
		{
			get
			{
				return (ConditionCollection)base.GetValue(ConditionalExpression.ConditionsProperty);
			}
		}
		public ConditionalExpression()
		{
			base.SetValue(ConditionalExpression.ConditionsProperty, new ConditionCollection());
		}
		public bool Evaluate()
		{
			bool flag = false;
			using (IEnumerator<ComparisonCondition> enumerator = this.Conditions.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					ComparisonCondition current = enumerator.get_Current();
					if (!(flag = current.Evaluate()) && this.ForwardChaining == ForwardChaining.And)
					{
						bool result = flag;
						return result;
					}
					if (flag && this.ForwardChaining == ForwardChaining.Or)
					{
						bool result = flag;
						return result;
					}
				}
			}
			return flag;
		}
	}
}
